package cn.aylog.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

import java.util.Arrays;

@Component
@Aspect
public class CallLog {

    @Around("execution(* cn.aylog.service..*(..))")
    public Object around(ProceedingJoinPoint point) {
        try {
            // point.getSignature() 获取目标类相关信息
            System.out.println("[" + point.getSignature().getDeclaringTypeName() + "]-"
                    + point.getSignature().getName() + " -> "
                    + Arrays.toString(point.getArgs()));
            Object ret = point.proceed(point.getArgs());
            return ret;
        } catch (Throwable e) {
            e.printStackTrace();
        }

        return null;
    }
}
